//
//                           SimuLTE
//
// This file is part of a software released under the license included in file
// "license.pdf". This license can be also found at http://www.ltesimulator.com/
// The above file and the present reference are part of the software itself,
// and cannot be removed from it.
//

#include "stack/mac/amc/LteMcs.h"

/**
 * <CQI Index [0-15]> , <Modulation> , <Code Rate x 1024>
 * This table contains value taken from the table 7.2.3-1 (TS 36.213)
 */
const CQIelem cqiTable[] =
    {
        CQIelem(_QPSK, 0.0),
        CQIelem(_QPSK, 78.0),
        CQIelem(_QPSK, 120.0),
        CQIelem(_QPSK, 193.0),
        CQIelem(_QPSK, 308.0),
        CQIelem(_QPSK, 449.0),
        CQIelem(_QPSK, 602.0),
        CQIelem(_16QAM, 378.0),
        CQIelem(_16QAM, 490.0),
        CQIelem(_16QAM, 616.0),
        CQIelem(_64QAM, 466.0),
        CQIelem(_64QAM, 567.0),
        CQIelem(_64QAM, 666.0),
        CQIelem(_64QAM, 772.0),
        CQIelem(_64QAM, 873.0),
        CQIelem(_64QAM, 948.0),
    };

/**
 * <MCS Index> , <Modulation> , <I-TBS> , <threshold>
 * This table contains value taken from (TS 36.213)
 */
McsTable::McsTable()
{
    table[0] = MCSelem(_QPSK, 0, 86.08);
    table[1] = MCSelem(_QPSK, 1, 112.80);
    table[2] = MCSelem(_QPSK, 2, 138.65);
    table[3] = MCSelem(_QPSK, 3, 179.48);
    table[4] = MCSelem(_QPSK, 4, 219.96);
    table[5] = MCSelem(_QPSK, 5, 269.86);
    table[6] = MCSelem(_QPSK, 6, 319.55);
    table[7] = MCSelem(_QPSK, 7, 374.48);
    table[8] = MCSelem(_QPSK, 8, 428.59);
    table[9] = MCSelem(_QPSK, 9, 483.37);
    table[10] = MCSelem(_16QAM, 9, 241.69);
    table[11] = MCSelem(_16QAM, 10, 268.80);
    table[12] = MCSelem(_16QAM, 11, 308.55);
    table[13] = MCSelem(_16QAM, 12, 349.13);
    table[14] = MCSelem(_16QAM, 13, 393.42);
    table[15] = MCSelem(_16QAM, 14, 437.91);
    table[16] = MCSelem(_16QAM, 15, 468.67);
    table[17] = MCSelem(_64QAM, 15, 312.45);
    table[18] = MCSelem(_64QAM, 16, 331.66);
    table[19] = MCSelem(_64QAM, 17, 367.66);
    table[20] = MCSelem(_64QAM, 18, 403.41);
    table[21] = MCSelem(_64QAM, 19, 438.55);
    table[22] = MCSelem(_64QAM, 20, 473.85);
    table[23] = MCSelem(_64QAM, 21, 511.28);
    table[24] = MCSelem(_64QAM, 22, 549.29);
    table[25] = MCSelem(_64QAM, 23, 583.51);
    table[26] = MCSelem(_64QAM, 24, 621.36);
    table[27] = MCSelem(_64QAM, 25, 646.43);
    table[28] = MCSelem(_64QAM, 26, 749.52);
}

void McsTable::rescale(const double scale)
{
    if (scale <= 0)
        throw cRuntimeError("Bad Rescaling value: %f", scale);

    for (Tbs i = 0; i < CQI2ITBSSIZE; ++i)
    {
        table[i].threshold_ *= (168.0 / scale);
    }
}

/********************************************
 *      ITBS 2 TBS FRIGHTENING TABLES
 ********************************************/

const unsigned int itbs2tbs_qpsk_1[][110] =
{
    {16,32,56,88,120,152,176,208,224,256,288,328,344,376,392,424,456,488,504,536,568,600,616,648,680,712,744,776,776,808,840,872,904,936,968,1000,1032,1032,1064,1096,1128,1160,1192,1224,1256,1256,1288,1320,1352,1384,1416,1416,1480,1480,1544,1544,1608,1608,1608,1672,1672,1736,1736,1800,1800,1800,1864,1864,1928,1928,1992,1992,2024,2088,2088,2088,2152,2152,2216,2216,2280,2280,2280,2344,2344,2408,2408,2472,2472,2536,2536,2536,2600,2600,2664,2664,2728,2728,2728,2792,2792,2856,2856,2856,2984,2984,2984,2984,2984,3112},
    {24,56,88,144,176,208,224,256,328,344,376,424,456,488,520,568,600,632,680,712,744,776,808,872,904,936,968,1000,1032,1064,1128,1160,1192,1224,1256,1288,1352,1384,1416,1416,1480,1544,1544,1608,1608,1672,1736,1736,1800,1800,1864,1864,1928,1992,1992,2024,2088,2088,2152,2152,2216,2280,2280,2344,2344,2408,2472,2472,2536,2536,2600,2600,2664,2728,2728,2792,2792,2856,2856,2856,2984,2984,2984,3112,3112,3112,3240,3240,3240,3240,3368,3368,3368,3496,3496,3496,3496,3624,3624,3624,3752,3752,3752,3752,3880,3880,3880,4008,4008,4008} ,
    {32,72,144,176,208,256,296,328,376,424,472,520,568,616,648,696,744,776,840,872,936,968,1000,1064,1096,1160,1192,1256,1288,1320,1384,1416,1480,1544,1544,1608,1672,1672,1736,1800,1800,1864,1928,1992,2024,2088,2088,2152,2216,2216,2280,2344,2344,2408,2472,2536,2536,2600,2664,2664,2728,2792,2856,2856,2856,2984,2984,3112,3112,3112,3240,3240,3240,3368,3368,3368,3496,3496,3496,3624,3624,3624,3752,3752,3880,3880,3880,4008,4008,4008,4136,4136,4136,4264,4264,4264,4392,4392,4392,4584,4584,4584,4584,4584,4776,4776,4776,4776,4968,4968 },
    {40,104,176,208,256,328,392,440,504,568,616,680,744,808,872,904,968,1032,1096,1160,1224,1256,1320,1384,1416,1480,1544,1608,1672,1736,1800,1864,1928,1992,2024,2088,2152,2216,2280,2344,2408,2472,2536,2536,2600,2664,2728,2792,2856,2856,2984,2984,3112,3112,3240,3240,3368,3368,3496,3496,3624,3624,3624,3752,3752,3880,3880,4008,4008,4136,4136,4264,4264,4392,4392,4392,4584,4584,4584,4776,4776,4776,4776,4968,4968,4968,5160,5160,5160,5352,5352,5352,5352,5544,5544,5544,5736,5736,5736,5736,5992,5992,5992,5992,6200,6200,6200,6200,6456,6456 },
    {56,120,208,256,328,408,488,552,632,696,776,840,904,1000,1064,1128,1192,1288,1352,1416,1480,1544,1608,1736,1800,1864,1928,1992,2088,2152,2216,2280,2344,2408,2472,2600,2664,2728,2792,2856,2984,2984,3112,3112,3240,3240,3368,3496,3496,3624,3624,3752,3752,3880,4008,4008,4136,4136,4264,4264,4392,4392,4584,4584,4584,4776,4776,4968,4968,4968,5160,5160,5160,5352,5352,5544,5544,5544,5736,5736,5736,5992,5992,5992,5992,6200,6200,6200,6456,6456,6456,6456,6712,6712,6712,6968,6968,6968,6968,7224,7224,7224,7480,7480,7480,7480,7736,7736,7736,7992},
    {72,144,224,328,424,504,600,680,776,872,968,1032,1128,1224,1320,1384,1480,1544,1672,1736,1864,1928,2024,2088,2216,2280,2344,2472,2536,2664,2728,2792,2856,2984,3112,3112,3240,3368,3496,3496,3624,3752,3752,3880,4008,4008,4136,4264,4392,4392,4584,4584,4776,4776,4776,4968,4968,5160,5160,5352,5352,5544,5544,5736,5736,5736,5992,5992,5992,6200,6200,6200,6456,6456,6712,6712,6712,6968,6968,6968,7224,7224,7224,7480,7480,7480,7736,7736,7736,7992,7992,7992,8248,8248,8248,8504,8504,8760,8760,8760,8760,9144,9144,9144,9144,9528,9528,9528,9528,9528},
    {88,176,256,392,504,600,712,808,936,1032,1128,1224,1352,1480,1544,1672,1736,1864,1992,2088,2216,2280,2408,2472,2600,2728,2792,2984,2984,3112,3240,3368,3496,3496,3624,3752,3880,4008,4136,4136,4264,4392,4584,4584,4776,4776,4968,4968,5160,5160,5352,5352,5544,5736,5736,5992,5992,5992,6200,6200,6456,6456,6456,6712,6712,6968,6968,6968,7224,7224,7480,7480,7736,7736,7736,7992,7992,8248,8248,8248,8504,8504,8760,8760,8760,9144,9144,9144,9144,9528,9528,9528,9528,9912,9912,9912,10296,10296,10296,10296,10680,10680,10680,10680,11064,11064,11064,11448,11448,11448},
    {104,224,328,472,584,712,840,968,1096,1224,1320,1480,1608,1672,1800,1928,2088,2216,2344,2472,2536,2664,2792,2984,3112,3240,3368,3368,3496,3624,3752,3880,4008,4136,4264,4392,4584,4584,4776,4968,4968,5160,5352,5352,5544,5736,5736,5992,5992,6200,6200,6456,6456,6712,6712,6712,6968,6968,7224,7224,7480,7480,7736,7736,7992,7992,8248,8248,8504,8504,8760,8760,8760,9144,9144,9144,9528,9528,9528,9912,9912,9912,10296,10296,10296,10680,10680,10680,11064,11064,11064,11448,11448,11448,11448,11832,11832,11832,12216,12216,12216,12576,12576,12576,12960,12960,12960,12960,13536,13536},
    {120,256,392,536,680,808,968,1096,1256,1384,1544,1672,1800,1928,2088,2216,2344,2536,2664,2792,2984,3112,3240,3368,3496,3624,3752,3880,4008,4264,4392,4584,4584,4776,4968,4968,5160,5352,5544,5544,5736,5992,5992,6200,6200,6456,6456,6712,6968,6968,7224,7224,7480,7480,7736,7736,7992,7992,8248,8504,8504,8760,8760,9144,9144,9144,9528,9528,9528,9912,9912,9912,10296,10296,10680,10680,10680,11064,11064,11064,11448,11448,11448,11832,11832,12216,12216,12216,12576,12576,12576,12960,12960,12960,13536,13536,13536,13536,14112,14112,14112,14112,14688,14688,14688,14688,15264,15264,15264,15264},
    {136,296,456,616,776,936,1096,1256,1416,1544,1736,1864,2024,2216,2344,2536,2664,2856,2984,3112,3368,3496,3624,3752,4008,4136,4264,4392,4584,4776,4968,5160,5160,5352,5544,5736,5736,5992,6200,6200,6456,6712,6712,6968,6968,7224,7480,7480,7736,7992,7992,8248,8248,8504,8760,8760,9144,9144,9144,9528,9528,9912,9912,10296,10296,10296,10680,10680,11064,11064,11064,11448,11448,11832,11832,11832,12216,12216,12576,12576,12960,12960,12960,13536,13536,13536,13536,14112,14112,14112,14112,14688,14688,14688,15264,15264,15264,15264,15840,15840,15840,16416,16416,16416,16416,16992,16992,16992,16992,17568}
};

const unsigned int itbs2tbs_16qam_1[][110] =
{
    {136,296,456,616,776,936,1096,1256,1416,1544,1736,1864,2024,2216,2344,2536,2664,2856,2984,3112,3368,3496,3624,3752,4008,4136,4264,4392,4584,4776,4968,5160,5160,5352,5544,5736,5736,5992,6200,6200,6456,6712,6712,6968,6968,7224,7480,7480,7736,7992,7992,8248,8248,8504,8760,8760,9144,9144,9144,9528,9528,9912,9912,10296,10296,10296,10680,10680,11064,11064,11064,11448,11448,11832,11832,11832,12216,12216,12576,12576,12960,12960,12960,13536,13536,13536,13536,14112,14112,14112,14112,14688,14688,14688,15264,15264,15264,15264,15840,15840,15840,16416,16416,16416,16416,16992,16992,16992,16992,17568},
    {144,328,504,680,872,1032,1224,1384,1544,1736,1928,2088,2280,2472,2664,2792,2984,3112,3368,3496,3752,3880,4008,4264,4392,4584,4776,4968,5160,5352,5544,5736,5736,5992,6200,6200,6456,6712,6712,6968,7224,7480,7480,7736,7992,7992,8248,8504,8504,8760,9144,9144,9144,9528,9528,9912,9912,10296,10296,10680,10680,11064,11064,11448,11448,11448,11832,11832,12216,12216,12576,12576,12960,12960,12960,13536,13536,13536,14112,14112,14112,14688,14688,14688,14688,15264,15264,15264,15840,15840,15840,16416,16416,16416,16992,16992,16992,16992,17568,17568,17568,18336,18336,18336,18336,18336,19080,19080,19080,19080},
    {176,376,584,776,1000,1192,1384,1608,1800,2024,2216,2408,2600,2792,2984,3240,3496,3624,3880,4008,4264,4392,4584,4776,4968,5352,5544,5736,5992,5992,6200,6456,6712,6968,6968,7224,7480,7736,7736,7992,8248,8504,8760,8760,9144,9144,9528,9528,9912,9912,10296,10680,10680,11064,11064,11448,11448,11832,11832,12216,12216,12576,12576,12960,12960,13536,13536,13536,14112,14112,14112,14688,14688,14688,15264,15264,15840,15840,15840,16416,16416,16416,16992,16992,16992,17568,17568,17568,18336,18336,18336,18336,19080,19080,19080,19080,19848,19848,19848,19848,20616,20616,20616,21384,21384,21384,21384,22152,22152,22152},
    {208,440,680,904,1128,1352,1608,1800,2024,2280,2472,2728,2984,3240,3368,3624,3880,4136,4392,4584,4776,4968,5352,5544,5736,5992,6200,6456,6712,6712,6968,7224,7480,7736,7992,8248,8504,8760,8760,9144,9528,9528,9912,9912,10296,10680,10680,11064,11064,11448,11832,11832,12216,12216,12576,12576,12960,12960,13536,13536,14112,14112,14112,14688,14688,15264,15264,15264,15840,15840,16416,16416,16416,16992,16992,17568,17568,17568,18336,18336,18336,19080,19080,19080,19080,19848,19848,19848,20616,20616,20616,21384,21384,21384,21384,22152,22152,22152,22920,22920,22920,23688,23688,23688,23688,24496,24496,24496,24496,25456},
    {224,488,744,1000,1256,1544,1800,2024,2280,2536,2856,3112,3368,3624,3880,4136,4392,4584,4968,5160,5352,5736,5992,6200,6456,6712,6968,7224,7480,7736,7992,8248,8504,8760,9144,9144,9528,9912,9912,10296,10680,10680,11064,11448,11448,11832,12216,12216,12576,12960,12960,13536,13536,14112,14112,14688,14688,14688,15264,15264,15840,15840,16416,16416,16992,16992,16992,17568,17568,18336,18336,18336,19080,19080,19080,19848,19848,19848,20616,20616,20616,21384,21384,21384,22152,22152,22152,22920,22920,22920,23688,23688,23688,24496,24496,24496,25456,25456,25456,25456,26416,26416,26416,26416,27376,27376,27376,27376,28336,28336},
    {256,552,840,1128,1416,1736,1992,2280,2600,2856,3112,3496,3752,4008,4264,4584,4968,5160,5544,5736,5992,6200,6456,6968,7224,7480,7736,7992,8248,8504,8760,9144,9528,9912,9912,10296,10680,11064,11064,11448,11832,12216,12216,12576,12960,12960,13536,13536,14112,14112,14688,14688,15264,15264,15840,15840,16416,16416,16992,16992,17568,17568,18336,18336,18336,19080,19080,19848,19848,19848,20616,20616,20616,21384,21384,22152,22152,22152,22920,22920,22920,23688,23688,24496,24496,24496,25456,25456,25456,25456,26416,26416,26416,27376,27376,27376,28336,28336,28336,28336,29296,29296,29296,29296,30576,30576,30576,30576,31704,31704},
    {280,600,904,1224,1544,1800,2152,2472,2728,3112,3368,3624,4008,4264,4584,4968,5160,5544,5736,6200,6456,6712,6968,7224,7736,7992,8248,8504,8760,9144,9528,9912,10296,10296,10680,11064,11448,11832,11832,12216,12576,12960,12960,13536,13536,14112,14688,14688,15264,15264,15840,15840,16416,16416,16992,16992,17568,17568,18336,18336,18336,19080,19080,19848,19848,20616,20616,20616,21384,21384,22152,22152,22152,22920,22920,23688,23688,23688,24496,24496,24496,25456,25456,25456,26416,26416,26416,27376,27376,27376,28336,28336,28336,29296,29296,29296,29296,30576,30576,30576,30576,31704,31704,31704,31704,32856,32856,32856,34008,34008}
};

const unsigned int itbs2tbs_64qam_1[][110] =
{
    {280,600,904,1224,1544,1800,2152,2472,2728,3112,3368,3624,4008,4264,4584,4968,5160,5544,5736,6200,6456,6712,6968,7224,7736,7992,8248,8504,8760,9144,9528,9912,10296,10296,10680,11064,11448,11832,11832,12216,12576,12960,12960,13536,13536,14112,14688,14688,15264,15264,15840,15840,16416,16416,16992,16992,17568,17568,18336,18336,18336,19080,19080,19848,19848,20616,20616,20616,21384,21384,22152,22152,22152,22920,22920,23688,23688,23688,24496,24496,24496,25456,25456,25456,26416,26416,26416,27376,27376,27376,28336,28336,28336,29296,29296,29296,29296,30576,30576,30576,30576,31704,31704,31704,31704,32856,32856,32856,34008,34008},
    {328,632,968,1288,1608,1928,2280,2600,2984,3240,3624,3880,4264,4584,4968,5160,5544,5992,6200,6456,6712,7224,7480,7736,7992,8504,8760,9144,9528,9912,9912,10296,10680,11064,11448,11832,12216,12216,12576,12960,13536,13536,14112,14112,14688,14688,15264,15840,15840,16416,16416,16992,16992,17568,17568,18336,18336,19080,19080,19848,19848,19848,20616,20616,21384,21384,22152,22152,22152,22920,22920,23688,23688,24496,24496,24496,25456,25456,25456,26416,26416,26416,27376,27376,27376,28336,28336,28336,29296,29296,29296,30576,30576,30576,30576,31704,31704,31704,31704,32856,32856,32856,34008,34008,34008,34008,35160,35160,35160,35160},
    {336,696,1064,1416,1800,2152,2536,2856,3240,3624,4008,4392,4776,5160,5352,5736,6200,6456,6712,7224,7480,7992,8248,8760,9144,9528,9912,10296,10296,10680,11064,11448,11832,12216,12576,12960,13536,13536,14112,14688,14688,15264,15264,15840,16416,16416,16992,17568,17568,18336,18336,19080,19080,19848,19848,20616,20616,20616,21384,21384,22152,22152,22920,22920,23688,23688,24496,24496,24496,25456,25456,26416,26416,26416,27376,27376,27376,28336,28336,29296,29296,29296,30576,30576,30576,30576,31704,31704,31704,32856,32856,32856,34008,34008,34008,35160,35160,35160,35160,36696,36696,36696,36696,37888,37888,37888,39232,39232,39232,39232},
    {376,776,1160,1544,1992,2344,2792,3112,3624,4008,4392,4776,5160,5544,5992,6200,6712,7224,7480,7992,8248,8760,9144,9528,9912,10296,10680,11064,11448,11832,12216,12576,12960,13536,14112,14112,14688,15264,15264,15840,16416,16416,16992,17568,17568,18336,18336,19080,19080,19848,19848,20616,21384,21384,22152,22152,22920,22920,23688,23688,24496,24496,24496,25456,25456,26416,26416,27376,27376,27376,28336,28336,29296,29296,29296,30576,30576,30576,31704,31704,31704,32856,32856,32856,34008,34008,34008,35160,35160,35160,36696,36696,36696,37888,37888,37888,37888,39232,39232,39232,40576,40576,40576,40576,42368,42368,42368,42368,43816,43816},
    {408,840,1288,1736,2152,2600,2984,3496,3880,4264,4776,5160,5544,5992,6456,6968,7224,7736,8248,8504,9144,9528,9912,10296,10680,11064,11448,12216,12576,12960,13536,13536,14112,14688,15264,15264,15840,16416,16992,16992,17568,18336,18336,19080,19080,19848,20616,20616,21384,21384,22152,22152,22920,22920,23688,24496,24496,25456,25456,25456,26416,26416,27376,27376,28336,28336,29296,29296,29296,30576,30576,30576,31704,31704,32856,32856,32856,34008,34008,34008,35160,35160,35160,36696,36696,36696,37888,37888,37888,39232,39232,39232,40576,40576,40576,40576,42368,42368,42368,43816,43816,43816,43816,45352,45352,45352,46888,46888,46888,46888},
    {440,904,1384,1864,2344,2792,3240,3752,4136,4584,5160,5544,5992,6456,6968,7480,7992,8248,8760,9144,9912,10296,10680,11064,11448,12216,12576,12960,13536,14112,14688,14688,15264,15840,16416,16992,16992,17568,18336,18336,19080,19848,19848,20616,20616,21384,22152,22152,22920,22920,23688,24496,24496,25456,25456,26416,26416,27376,27376,28336,28336,29296,29296,29296,30576,30576,31704,31704,31704,32856,32856,34008,34008,34008,35160,35160,35160,36696,36696,36696,37888,37888,39232,39232,39232,40576,40576,40576,42368,42368,42368,42368,43816,43816,43816,45352,45352,45352,46888,46888,46888,46888,48936,48936,48936,48936,48936,51024,51024,51024},
    {488,1000,1480,1992,2472,2984,3496,4008,4584,4968,5544,5992,6456,6968,7480,7992,8504,9144,9528,9912,10680,11064,11448,12216,12576,12960,13536,14112,14688,15264,15840,15840,16416,16992,17568,18336,18336,19080,19848,19848,20616,21384,21384,22152,22920,22920,23688,24496,24496,25456,25456,26416,26416,27376,27376,28336,28336,29296,29296,30576,30576,31704,31704,31704,32856,32856,34008,34008,35160,35160,35160,36696,36696,36696,37888,37888,39232,39232,39232,40576,40576,40576,42368,42368,42368,43816,43816,43816,45352,45352,45352,46888,46888,46888,46888,48936,48936,48936,48936,51024,51024,51024,51024,52752,52752,52752,52752,55056,55056,55056},
    {520,1064,1608,2152,2664,3240,3752,4264,4776,5352,5992,6456,6968,7480,7992,8504,9144,9528,10296,10680,11448,11832,12576,12960,13536,14112,14688,15264,15840,16416,16992,16992,17568,18336,19080,19080,19848,20616,21384,21384,22152,22920,22920,23688,24496,24496,25456,25456,26416,27376,27376,28336,28336,29296,29296,30576,30576,31704,31704,32856,32856,34008,34008,34008,35160,35160,36696,36696,36696,37888,37888,39232,39232,40576,40576,40576,42368,42368,42368,43816,43816,43816,45352,45352,45352,46888,46888,46888,48936,48936,48936,48936,51024,51024,51024,51024,52752,52752,52752,55056,55056,55056,55056,57336,57336,57336,57336,59256,59256,59256},
    {552,1128,1736,2280,2856,3496,4008,4584,5160,5736,6200,6968,7480,7992,8504,9144,9912,10296,11064,11448,12216,12576,12960,13536,14112,14688,15264,15840,16416,16992,17568,18336,19080,19848,19848,20616,21384,22152,22152,22920,23688,24496,24496,25456,25456,26416,27376,27376,28336,28336,29296,29296,30576,30576,31704,31704,32856,32856,34008,34008,35160,35160,36696,36696,37888,37888,37888,39232,39232,40576,40576,40576,42368,42368,43816,43816,43816,45352,45352,45352,46888,46888,46888,48936,48936,48936,51024,51024,51024,51024,52752,52752,52752,55056,55056,55056,55056,57336,57336,57336,57336,59256,59256,59256,59256,61664,61664,61664,61664,63776},
    {584,1192,1800,2408,2984,3624,4264,4968,5544,5992,6712,7224,7992,8504,9144,9912,10296,11064,11448,12216,12960,13536,14112,14688,15264,15840,16416,16992,17568,18336,19080,19848,19848,20616,21384,22152,22920,22920,23688,24496,25456,25456,26416,26416,27376,28336,28336,29296,29296,30576,31704,31704,32856,32856,34008,34008,35160,35160,36696,36696,36696,37888,37888,39232,39232,40576,40576,42368,42368,42368,43816,43816,45352,45352,45352,46888,46888,46888,48936,48936,48936,51024,51024,51024,52752,52752,52752,52752,55056,55056,55056,57336,57336,57336,57336,59256,59256,59256,61664,61664,61664,61664,63776,63776,63776,63776,66592,66592,66592,66592},
    {616,1256,1864,2536,3112,3752,4392,5160,5736,6200,6968,7480,8248,8760,9528,10296,10680,11448,12216,12576,13536,14112,14688,15264,15840,16416,16992,17568,18336,19080,19848,20616,20616,21384,22152,22920,23688,24496,24496,25456,26416,26416,27376,28336,28336,29296,29296,30576,31704,31704,32856,32856,34008,34008,35160,35160,36696,36696,37888,37888,39232,39232,40576,40576,40576,42368,42368,43816,43816,43816,45352,45352,46888,46888,46888,48936,48936,48936,51024,51024,51024,52752,52752,52752,55056,55056,55056,55056,57336,57336,57336,59256,59256,59256,61664,61664,61664,61664,63776,63776,63776,63776,66592,66592,66592,66592,68808,68808,68808,71112},
    {712,1480,2216,2984,3752,4392,5160,5992,6712,7480,8248,8760,9528,10296,11064,11832,12576,13536,14112,14688,15264,16416,16992,17568,18336,19080,19848,20616,21384,22152,22920,23688,24496,25456,25456,26416,27376,28336,29296,29296,30576,30576,31704,32856,32856,34008,35160,35160,36696,36696,37888,37888,39232,40576,40576,40576,42368,42368,43816,43816,45352,45352,46888,46888,48936,48936,48936,51024,51024,52752,52752,52752,55056,55056,55056,55056,57336,57336,57336,59256,59256,59256,61664,61664,61664,63776,63776,63776,66592,66592,66592,68808,68808,68808,71112,71112,71112,73712,73712,75376,75376,75376,75376,75376,75376,75376,75376,75376,75376,75376}
};

const unsigned int itbs2tbs_qpsk_2[][110] =
{
    {32,64,112,176,240,304,352,416,448,512,576,656,688,752,784,848,912,976,1008,1072,1136,1200,1232,1296,1360,1424,1488,1552,1552,1616,1680,1744,1808,1872,1936,2000,2064,2064,2128,2192,2256,2320,2384,2448,2512,2512,2576,2640,2704,2768,2832,2832,2960,2960,3088,3088,3240,3240,3240,3368,3368,3496,3496,3624,3624,3624,3752,3752,3880,3880,4008,4008,4008,4136,4136,4136,4264,4264,4392,4392,4584,4584,4584,4776,4776,4776,4776,4968,4968,5160,5160,5160,5160,5160,5352,5352,5544,5544,5544,5544,5544,5736,5736,5736,5992,5992,5992,5992,5992,6200,},
    {48,112,176,288,352,416,448,512,656,688,752,848,912,976,1040,1136,1200,1264,1360,1424,1488,1552,1616,1744,1808,1872,1936,2000,2064,2128,2256,2320,2384,2448,2512,2576,2704,2768,2832,2832,2960,3088,3088,3216,3216,3344,3472,3472,3600,3600,3728,3728,3856,3984,3984,4048,4136,4136,4264,4264,4392,4584,4584,4776,4776,4776,4968,4968,5160,5160,5160,5160,5352,5544,5544,5544,5544,5736,5736,5736,5992,5992,5992,6200,6200,6200,6456,6456,6456,6456,6712,6712,6712,6968,6968,6968,6968,7224,7224,7224,7480,7480,7480,7480,7736,7736,7736,7992,7992,7992,},
    {64,144,288,352,416,512,592,656,752,848,944,1040,1136,1232,1296,1392,1488,1552,1680,1744,1872,1936,2000,2128,2192,2320,2384,2512,2576,2640,2768,2832,2960,3088,3088,3216,3344,3344,3472,3600,3600,3728,3856,3984,4048,4176,4176,4304,4432,4432,4560,4688,4688,4816,4944,5072,5160,5160,5352,5352,5544,5544,5736,5736,5736,5992,5992,6200,6200,6200,6456,6456,6456,6712,6712,6712,6968,6968,6968,7224,7224,7224,7480,7480,7736,7736,7736,7992,7992,7992,8248,8248,8248,8504,8504,8504,8760,8760,8760,9144,9144,9144,9144,9144,9528,9528,9528,9528,9912,9912,},
    {80,208,352,416,512,656,784,880,1008,1136,1232,1360,1488,1616,1744,1808,1936,2064,2192,2320,2448,2512,2640,2768,2832,2960,3088,3216,3344,3472,3600,3728,3856,3984,4048,4176,4304,4432,4560,4688,4816,4944,5072,5072,5200,5328,5456,5584,5712,5712,5968,5968,6224,6224,6480,6480,6712,6712,6968,6968,7224,7224,7224,7480,7480,7736,7736,7992,7992,8248,8248,8504,8504,8760,8760,8760,9144,9144,9144,9528,9528,9528,9528,9912,9912,9912,10296,10296,10296,10680,10680,10680,10680,11064,11064,11064,11448,11448,11448,11448,11832,11832,11832,11832,12576,12576,12576,12576,12960,12960,},
    {112,240,416,512,656,816,976,1104,1264,1392,1552,1680,1808,2000,2128,2256,2384,2576,2704,2832,2960,3088,3216,3472,3600,3728,3856,3984,4176,4304,4432,4560,4688,4816,4944,5200,5328,5456,5584,5712,5968,5968,6224,6224,6480,6480,6736,6992,6992,7248,7248,7504,7504,7760,8016,8016,8248,8248,8504,8504,8760,8760,9144,9144,9144,9528,9528,9912,9912,9912,10296,10296,10296,10680,10680,11064,11064,11064,11448,11448,11448,11832,11832,11832,11832,12576,12576,12576,12960,12960,12960,12960,13536,13536,13536,14112,14112,14112,14112,14688,14688,14688,14688,14688,14688,14688,15264,15264,15264,15840,},
    {144,288,448,656,848,1008,1200,1360,1552,1744,1936,2064,2256,2448,2640,2768,2960,3088,3344,3472,3728,3856,4048,4176,4432,4560,4688,4944,5072,5328,5456,5584,5712,5968,6224,6224,6480,6736,6992,6992,7248,7504,7504,7760,8016,8016,8272,8528,8784,8784,9168,9168,9552,9552,9552,9936,9912,10296,10296,10680,10680,11064,11064,11448,11448,11448,11832,11832,11832,12576,12576,12576,12960,12960,13536,13536,13536,14112,14112,14112,14688,14688,14688,14688,14688,14688,15264,15264,15264,15840,15840,15840,16416,16416,16416,16992,16992,17568,17568,17568,17568,18336,18336,18336,18336,19080,19080,19080,19080,19080,},
    {176,352,512,784,1008,1200,1424,1616,1872,2064,2256,2448,2704,2960,3088,3344,3472,3728,3984,4176,4432,4560,4816,4944,5200,5456,5584,5968,5968,6224,6480,6736,6992,6992,7248,7504,7760,8016,8272,8272,8528,8784,9168,9168,9552,9552,9936,9936,10320,10320,10704,10704,11088,11472,11472,11984,11832,11832,12576,12576,12960,12960,12960,13536,13536,14112,14112,14112,14688,14688,14688,14688,15264,15264,15264,15840,15840,16416,16416,16416,16992,16992,17568,17568,17568,18336,18336,18336,18336,19080,19080,19080,19080,19848,19848,19848,20616,20616,20616,20616,21384,21384,21384,21384,22152,22152,22152,22920,22920,22920,},
    {208,448,656,944,1168,1424,1680,1936,2192,2448,2640,2960,3216,3344,3600,3856,4176,4432,4688,4944,5072,5328,5584,5968,6224,6480,6736,6736,6992,7248,7504,7760,8016,8272,8528,8784,9168,9168,9552,9936,9936,10320,10704,10704,11088,11472,11472,11984,11984,12400,12400,12912,12912,13424,13424,13424,14112,14112,14688,14688,14688,14688,15264,15264,15840,15840,16416,16416,16992,16992,17568,17568,17568,18336,18336,18336,19080,19080,19080,19848,19848,19848,20616,20616,20616,21384,21384,21384,22152,22152,22152,22920,22920,22920,22920,23688,23688,23688,24496,24496,24496,25456,25456,25456,25456,25456,25456,25456,27376,27376,},
    {240,512,784,1072,1360,1616,1936,2192,2512,2768,3088,3344,3600,3856,4176,4432,4688,5072,5328,5584,5968,6224,6480,6736,6992,7248,7504,7760,8016,8528,8784,9168,9168,9552,9936,9936,10320,10704,11088,11088,11472,11984,11984,12400,12400,12912,12912,13424,13936,13936,14448,14448,14960,14960,15472,15472,15840,15840,16416,16992,16992,17568,17568,18336,18336,18336,19080,19080,19080,19848,19848,19848,20616,20616,21384,21384,21384,22152,22152,22152,22920,22920,22920,23688,23688,24496,24496,24496,25456,25456,25456,25456,25456,25456,27376,27376,27376,27376,28336,28336,28336,28336,29296,29296,29296,29296,30576,30576,30576,30576,},
    {272,592,912,1232,1552,1872,2192,2512,2832,3088,3472,3728,4048,4432,4688,5072,5328,5712,5968,6224,6736,6992,7248,7504,8016,8272,8528,8784,9168,9552,9936,10320,10320,10704,11088,11472,11472,11984,12400,12400,12912,13424,13424,13936,13936,14448,14960,14960,15472,15984,15984,16496,16496,17008,17520,17520,18336,18336,18336,19080,19080,19848,19848,20616,20616,20616,21384,21384,22152,22152,22152,22920,22920,23688,23688,23688,24496,24496,25456,25456,25456,25456,25456,27376,27376,27376,27376,28336,28336,28336,28336,29296,29296,29296,30576,30576,30576,30576,31704,31704,31704,32856,32856,32856,32856,34008,34008,34008,34008,35160,}
};

const unsigned int itbs2tbs_16qam_2[][110] =
{
    {272,592,912,1232,1552,1872,2192,2512,2832,3088,3472,3728,4048,4432,4688,5072,5328,5712,5968,6224,6736,6992,7248,7504,8016,8272,8528,8784,9168,9552,9936,10320,10320,10704,11088,11472,11472,11984,12400,12400,12912,13424,13424,13936,13936,14448,14960,14960,15472,15984,15984,16496,16496,17008,17520,17520,18336,18336,18336,19080,19080,19848,19848,20616,20616,20616,21384,21384,22152,22152,22152,22920,22920,23688,23688,23688,24496,24496,25456,25456,25456,25456,25456,27376,27376,27376,27376,28336,28336,28336,28336,29296,29296,29296,30576,30576,30576,30576,31704,31704,31704,32856,32856,32856,32856,34008,34008,34008,34008,35160,},
    {288,656,1008,1360,1744,2064,2448,2768,3088,3472,3856,4176,4560,4944,5328,5584,5968,6224,6736,6992,7504,7760,8016,8528,8784,9168,9552,9936,10320,10704,11088,11472,11472,11984,12400,12400,12912,13424,13424,13936,14448,14960,14960,15472,15984,15984,16496,17008,17008,17520,18288,18288,18288,19056,19056,19824,19848,20616,20616,21384,21384,22152,22152,22920,22920,22920,23688,23688,24496,24496,25456,25456,25456,25456,25456,27376,27376,27376,28336,28336,28336,29296,29296,29296,29296,30576,30576,30576,31704,31704,31704,32856,32856,32856,34008,34008,34008,34008,35160,35160,35160,36696,36696,36696,36696,36696,37888,37888,37888,37888,},
    {352,752,1168,1552,2000,2384,2768,3216,3600,4048,4432,4816,5200,5584,5968,6480,6992,7248,7760,8016,8528,8784,9168,9552,9936,10704,11088,11472,11984,11984,12400,12912,13424,13936,13936,14448,14960,15472,15472,15984,16496,17008,17520,17520,18288,18288,19056,19056,19824,19824,20592,21360,21360,22128,22128,22896,22920,23688,23688,24496,24496,25456,25456,25456,25456,27376,27376,27376,28336,28336,28336,29296,29296,29296,30576,30576,31704,31704,31704,32856,32856,32856,34008,34008,34008,35160,35160,35160,36696,36696,36696,36696,37888,37888,37888,37888,39232,39232,39232,39232,40576,40576,40576,42368,42368,42368,42368,43816,43816,43816,},
    {416,880,1360,1808,2256,2704,3216,3600,4048,4560,4944,5456,5968,6480,6736,7248,7760,8272,8784,9168,9552,9936,10704,11088,11472,11984,12400,12912,13424,13424,13936,14448,14960,15472,15984,16496,17008,17520,17520,18288,19056,19056,19824,19824,20592,21360,21360,22128,22128,22896,23664,23664,24432,24432,25152,25152,25456,25456,27376,27376,28336,28336,28336,29296,29296,30576,30576,30576,31704,31704,32856,32856,32856,34008,34008,35160,35160,35160,36696,36696,36696,37888,37888,37888,37888,39232,39232,39232,40576,40576,40576,42368,42368,42368,42368,43816,43816,43816,45352,45352,45352,46888,46888,46888,46888,48936,48936,48936,48936,51024,},
    {448,976,1488,2000,2512,3088,3600,4048,4560,5072,5712,6224,6736,7248,7760,8272,8784,9168,9936,10320,10704,11472,11984,12400,12912,13424,13936,14448,14960,15472,15984,16496,17008,17520,18288,18288,19056,19824,19824,20592,21360,21360,22128,22896,22896,23664,24432,24432,25152,25920,25920,27072,27072,28224,28224,29376,29296,29296,30576,30576,31704,31704,32856,32856,34008,34008,34008,35160,35160,36696,36696,36696,37888,37888,37888,39232,39232,39232,40576,40576,40576,42368,42368,42368,43816,43816,43816,45352,45352,45352,46888,46888,46888,48936,48936,48936,51024,51024,51024,51024,52752,52752,52752,52752,55056,55056,55056,55056,57336,57336,},
    {512,1104,1680,2256,2832,3472,3984,4560,5200,5712,6224,6992,7504,8016,8528,9168,9936,10320,11088,11472,11984,12400,12912,13936,14448,14960,15472,15984,16496,17008,17520,18288,19056,19824,19824,20592,21360,22128,22128,22896,23664,24432,24432,25152,25920,25920,27072,27072,28224,28224,29376,29376,30528,30528,31680,31680,32856,32856,34008,34008,35160,35160,36696,36696,36696,37888,37888,39232,39232,39232,40576,40576,40576,42368,42368,43816,43816,43816,45352,45352,45352,46888,46888,48936,48936,48936,51024,51024,51024,51024,52752,52752,52752,55056,55056,55056,57336,57336,57336,57336,59256,59256,59256,59256,61664,61664,61664,61664,63776,63776,},
    {560,1200,1808,2448,3088,3600,4304,4944,5456,6224,6736,7248,8016,8528,9168,9936,10320,11088,11472,12400,12912,13424,13936,14448,15472,15984,16496,17008,17520,18288,19056,19824,20592,20592,21360,22128,22896,23664,23664,24432,25152,25920,25920,27072,27072,28224,29376,29376,30528,30528,31680,31680,32832,32832,33984,33984,35160,35160,36696,36696,36696,37888,37888,39232,39232,40576,40576,40576,42368,42368,43816,43816,43816,45352,45352,46888,46888,46888,48936,48936,48936,51024,51024,51024,52752,52752,52752,55056,55056,55056,57336,57336,57336,59256,59256,59256,59256,61664,61664,61664,61664,63776,63776,63776,63776,66592,66592,66592,68808,68808,}
};

const unsigned int itbs2tbs_64qam_2[][110] =
{
    {560,1200,1808,2448,3088,3600,4304,4944,5456,6224,6736,7248,8016,8528,9168,9936,10320,11088,11472,12400,12912,13424,13936,14448,15472,15984,16496,17008,17520,18288,19056,19824,20592,20592,21360,22128,22896,23664,23664,24432,25152,25920,25920,27072,27072,28224,29376,29376,30528,30528,31680,31680,32832,32832,33984,33984,35160,35160,36696,36696,36696,37888,37888,39232,39232,40576,40576,40576,42368,42368,43816,43816,43816,45352,45352,46888,46888,46888,48936,48936,48936,51024,51024,51024,52752,52752,52752,55056,55056,55056,57336,57336,57336,59256,59256,59256,59256,61664,61664,61664,61664,63776,63776,63776,63776,66592,66592,66592,68808,68808,},
    {656,1264,1936,2576,3216,3856,4560,5200,5968,6480,7248,7760,8528,9168,9936,10320,11088,11984,12400,12912,13424,14448,14960,15472,15984,17008,17520,18288,19056,19824,19824,20592,21360,22128,22896,23664,24432,24432,25152,25920,27072,27072,28224,28224,29376,29376,30528,31680,31680,32832,32832,33984,33984,35136,35136,36672,36696,37888,37888,39232,39232,39232,40576,40576,42368,42368,43816,43816,43816,45352,45352,46888,46888,48936,48936,48936,51024,51024,51024,52752,52752,52752,55056,55056,55056,57336,57336,57336,59256,59256,59256,61664,61664,61664,61664,63776,63776,63776,63776,66592,66592,66592,68808,68808,68808,68808,71112,71112,71112,71112,},
    {672,1392,2128,2832,3600,4304,5072,5712,6480,7248,8016,8784,9552,10320,10704,11472,12400,12912,13424,14448,14960,15984,16496,17520,18288,19056,19824,20592,20592,21360,22128,22896,23664,24432,25152,25920,27072,27072,28224,29376,29376,30528,30528,31680,32832,32832,33984,35136,35136,36672,36672,38160,38160,39696,39696,41232,40576,40576,42368,42368,43816,43816,45352,45352,46888,46888,48936,48936,48936,51024,51024,52752,52752,52752,55056,55056,55056,57336,57336,59256,59256,59256,61664,61664,61664,61664,63776,63776,63776,66592,66592,66592,68808,68808,68808,71112,71112,71112,71112,73712,73712,73712,73712,76208,76208,76208,78704,78704,78704,78704,},
    {752,1552,2320,3088,3984,4688,5584,6224,7248,8016,8784,9552,10320,11088,11984,12400,13424,14448,14960,15984,16496,17520,18288,19056,19824,20592,21360,22128,22896,23664,24432,25152,25920,27072,28224,28224,29376,30528,30528,31680,32832,32832,33984,35136,35136,36672,36672,38160,38160,39696,39696,41232,42768,42768,44304,44304,45352,45352,46888,46888,48936,48936,48936,51024,51024,52752,52752,55056,55056,55056,57336,57336,59256,59256,59256,61664,61664,61664,63776,63776,63776,66592,66592,66592,68808,68808,68808,71112,71112,71112,73712,73712,73712,76208,76208,76208,76208,78704,78704,78704,81176,81176,81176,81176,84760,84760,84760,84760,87936,87936,},
    {816,1680,2576,3472,4304,5200,5968,6992,7760,8528,9552,10320,11088,11984,12912,13936,14448,15472,16496,17008,18288,19056,19824,20592,21360,22128,22896,24432,25152,25920,27072,27072,28224,29376,30528,30528,31680,32832,33984,33984,35136,36672,36672,38160,38160,39696,41232,41232,42768,42768,44304,44304,45840,45840,47376,48992,48936,51024,51024,51024,52752,52752,55056,55056,57336,57336,59256,59256,59256,61664,61664,61664,63776,63776,66592,66592,66592,68808,68808,68808,71112,71112,71112,73712,73712,73712,76208,76208,76208,78704,78704,78704,81176,81176,81176,81176,84760,84760,84760,87936,87936,87936,87936,90816,90816,90816,93800,93800,93800,93800,},
    {880,1808,2768,3728,4688,5584,6480,7504,8272,9168,10320,11088,11984,12912,13936,14960,15984,16496,17520,18288,19824,20592,21360,22128,22896,24432,25152,25920,27072,28224,29376,29376,30528,31680,32832,33984,33984,35136,36672,36672,38160,39696,39696,41232,41232,42768,44304,44304,45840,45840,47376,48992,48992,50912,50912,52832,52752,55056,55056,57336,57336,59256,59256,59256,61664,61664,63776,63776,63776,66592,66592,68808,68808,68808,71112,71112,71112,73712,73712,73712,76208,76208,78704,78704,78704,81176,81176,81176,84760,84760,84760,84760,87936,87936,87936,90816,90816,90816,93800,93800,93800,93800,97896,97896,97896,97896,97896,101840,101840,101840,},
    {976,2000,2960,3984,4944,5968,6992,8016,9168,9936,11088,11984,12912,13936,14960,15984,17008,18288,19056,19824,21360,22128,22896,24432,25152,25920,27072,28224,29376,30528,31680,31680,32832,33984,35136,36672,36672,38160,39696,39696,41232,42768,42768,44304,45840,45840,47376,48992,48992,50912,50912,52832,52832,54752,54752,56672,57336,59256,59256,61664,61664,63776,63776,63776,66592,66592,68808,68808,71112,71112,71112,73712,73712,73712,76208,76208,78704,78704,78704,81176,81176,81176,84760,84760,84760,87936,87936,87936,90816,90816,90816,93800,93800,93800,93800,97896,97896,97896,97896,101840,101840,101840,101840,105528,105528,105528,105528,110136,110136,110136,},
    {1040,2128,3216,4304,5328,6480,7504,8528,9552,10704,11984,12912,13936,14960,15984,17008,18288,19056,20592,21360,22896,23664,25152,25920,27072,28224,29376,30528,31680,32832,33984,33984,35136,36672,38160,38160,39696,41232,42768,42768,44304,45840,45840,47376,48992,48992,50912,50912,52832,54752,54752,56672,56672,58592,58592,61152,61664,63776,63776,66592,66592,68808,68808,68808,71112,71112,73712,73712,73712,76208,76208,78704,78704,81176,81176,81176,84760,84760,84760,87936,87936,87936,90816,90816,90816,93800,93800,93800,97896,97896,97896,97896,101840,101840,101840,101840,105528,105528,105528,110136,110136,110136,110136,115040,115040,115040,115040,119816,119816,119816,},
    {1104,2256,3472,4560,5712,6992,8016,9168,10320,11472,12400,13936,14960,15984,17008,18288,19824,20592,22128,22896,24432,25152,25920,27072,28224,29376,30528,31680,32832,33984,35136,36672,38160,39696,39696,41232,42768,44304,44304,45840,47376,48992,48992,50912,50912,52832,54752,54752,56672,56672,58592,58592,61152,61152,63408,63408,66592,66592,68808,68808,71112,71112,73712,73712,76208,76208,76208,78704,78704,81176,81176,81176,84760,84760,87936,87936,87936,90816,90816,90816,93800,93800,93800,97896,97896,97896,101840,101840,101840,101840,105528,105528,105528,110136,110136,110136,110136,115040,115040,115040,115040,119816,119816,119816,119816,124464,124464,124464,124464,128496,},
    {1168,2384,3600,4816,5968,7248,8528,9936,11088,11984,13424,14448,15984,17008,18288,19824,20592,22128,22896,24432,25920,27072,28224,29376,30528,31680,32832,33984,35136,36672,38160,39696,39696,41232,42768,44304,45840,45840,47376,48992,50912,50912,52832,52832,54752,56672,56672,58592,58592,61152,63408,63408,65712,65712,68016,68016,71112,71112,73712,73712,73712,76208,76208,78704,78704,81176,81176,84760,84760,84760,87936,87936,90816,90816,90816,93800,93800,93800,97896,97896,97896,101840,101840,101840,105528,105528,105528,105528,110136,110136,110136,115040,115040,115040,115040,119816,119816,119816,124464,124464,124464,124464,128496,128496,128496,128496,133208,133208,133208,133208,},
    {1232,2512,3728,5072,6224,7504,8784,10320,11472,12400,13936,14960,16496,17520,19056,20592,21360,22896,24432,25152,27072,28224,29376,30528,31680,32832,33984,35136,36672,38160,39696,41232,41232,42768,44304,45840,47376,48992,48992,50912,52832,52832,54752,56672,56672,58592,58592,61152,63408,63408,65712,65712,68016,68016,70320,70320,73712,73712,76208,76208,78704,78704,81176,81176,81176,84760,84760,87936,87936,87936,90816,90816,93800,93800,93800,97896,97896,97896,101840,101840,101840,105528,105528,105528,110136,110136,110136,110136,115040,115040,115040,119816,119816,119816,124464,124464,124464,124464,128496,128496,128496,128496,133208,133208,133208,133208,137792,137792,137792,142248,},
    {1424,2960,4432,5968,7504,8784,10320,11984,13424,14960,16496,17520,19056,20592,22128,23664,25152,27072,28224,29376,30528,32832,33984,35136,36672,38160,39696,41232,42768,44304,45840,47376,48992,50912,50912,52832,54752,56672,58592,58592,61152,61152,63408,65712,65712,68016,70320,70320,73392,73392,75776,75776,78464,81152,81152,81152,84760,84760,87936,87936,90816,90816,93800,93800,97896,97896,97896,101840,101840,105528,105528,105528,110136,110136,110136,110136,115040,115040,115040,119816,119816,119816,124464,124464,124464,128496,128496,128496,133208,133208,133208,137792,137792,137792,142248,142248,142248,146856,146856,149776,149776,149776,149776,149776,149776,149776,149776,149776,149776,149776,}
};

const unsigned int itbs2tbs_qpsk_4[][110] =
{
    {64,128,224,352,480,608,704,832,896,1024,1152,1312,1376,1504,1568,1696,1824,1952,2016,2144,2272,2400,2464,2592,2720,2848,2976,3104,3104,3232,3360,3488,3616,3744,3872,4000,4128,4128,4256,4384,4512,4640,4768,4896,5024,5024,5152,5280,5408,5536,5664,5664,5920,5920,6176,6176,6432,6432,6432,6688,6688,6944,6944,7200,7200,7200,7456,7456,7712,7712,7968,7968,8096,8352,8352,8352,8608,8608,8864,8864,9120,9120,9120,9376,9376,9632,9632,9888,9888,10144,10144,10144,10400,10400,10656,10656,10912,10912,10912,11168,11168,11424,11424,11424,11936,11936,11936,11936,11936,12448},
    {96,224,352,576,704,832,896,1024,1312,1376,1504,1696,1824,1952,2080,2272,2400,2528,2720,2848,2976,3104,3232,3488,3616,3744,3872,4000,4128,4256,4512,4640,4768,4896,5024,5152,5408,5536,5664,5664,5920,6176,6176,6432,6432,6688,6944,6944,7200,7200,7456,7456,7712,7968,7968,8096,8352,8352,8608,8608,8864,9120,9120,9376,9376,9632,9888,9888,10144,10144,10400,10400,10656,10912,10912,11168,11168,11424,11424,11424,11936,11936,11936,12448,12448,12448,12960,12960,12960,12960,13472,13472,13472,13984,13984,13984,13984,14496,14496,14496,15008,15008,15008,15008,15520,15520,15520,16032,16032,16032},
    {128,288,576,704,832,1024,1184,1312,1504,1696,1888,2080,2272,2464,2592,2784,2976,3104,3360,3488,3744,3872,4000,4256,4384,4640,4768,5024,5152,5280,5536,5664,5920,6176,6176,6432,6688,6688,6944,7200,7200,7456,7712,7968,8096,8352,8352,8608,8864,8864,9120,9376,9376,9632,9888,10144,10144,10400,10656,10656,10912,11168,11424,11424,11424,11936,11936,12448,12448,12448,12960,12960,12960,13472,13472,13472,13984,13984,13984,14496,14496,14496,15008,15008,15520,15520,15520,16032,16032,16032,16544,16544,16544,17056,17056,17056,17568,17568,17568,18336,18336,18336,18336,18336,19104,19104,19104,19104,19872,19872},
    {160,416,704,832,1024,1312,1568,1760,2016,2272,2464,2720,2976,3232,3488,3616,3872,4128,4384,4640,4896,5024,5280,5536,5664,5920,6176,6432,6688,6944,7200,7456,7712,7968,8096,8352,8608,8864,9120,9376,9632,9888,10144,10144,10400,10656,10912,11168,11424,11424,11936,11936,12448,12448,12960,12960,13472,13472,13984,13984,14496,14496,14496,15008,15008,15520,15520,16032,16032,16544,16544,17056,17056,17568,17568,17568,18336,18336,18336,19104,19104,19104,19104,19872,19872,19872,20640,20640,20640,21408,21408,21408,21408,22176,22176,22176,22944,22944,22944,22944,23968,23968,23968,23968,24800,24800,24800,24800,25824,25824},
    {224,480,832,1024,1312,1632,1952,2208,2528,2784,3104,3360,3616,4000,4256,4512,4768,5152,5408,5664,5920,6176,6432,6944,7200,7456,7712,7968,8352,8608,8864,9120,9376,9632,9888,10400,10656,10912,11168,11424,11936,11936,12448,12448,12960,12960,13472,13984,13984,14496,14496,15008,15008,15520,16032,16032,16544,16544,17056,17056,17568,17568,18336,18336,18336,19104,19104,19872,19872,19872,20640,20640,20640,21408,21408,22176,22176,22176,22944,22944,22944,23968,23968,23968,23968,24800,24800,24800,25824,25824,25824,25824,26848,26848,26848,27872,27872,27872,27872,28896,28896,28896,29920,29920,29920,29920,30944,30944,30944,31968},
    {288,576,896,1312,1696,2016,2400,2720,3104,3488,3872,4128,4512,4896,5280,5536,5920,6176,6688,6944,7456,7712,8096,8352,8864,9120,9376,9888,10144,10656,10912,11168,11424,11936,12448,12448,12960,13472,13984,13984,14496,15008,15008,15520,16032,16032,16544,17056,17568,17568,18336,18336,19104,19104,19104,19872,19872,20640,20640,21408,21408,22176,22176,22944,22944,22944,23968,23968,23968,24800,24800,24800,25824,25824,26848,26848,26848,27872,27872,27872,28896,28896,28896,29920,29920,29920,30944,30944,30944,31968,31968,31968,32992,32992,32992,34016,34016,35040,35040,35040,35040,36576,36576,36576,36576,38112,38112,38112,38112,38112},
    {352,704,1024,1568,2016,2400,2848,3232,3744,4128,4512,4896,5408,5920,6176,6688,6944,7456,7968,8352,8864,9120,9632,9888,10400,10912,11168,11936,11936,12448,12960,13472,13984,13984,14496,15008,15520,16032,16544,16544,17056,17568,18336,18336,19104,19104,19872,19872,20640,20640,21408,21408,22176,22944,22944,23968,23968,23968,24800,24800,25824,25824,25824,26848,26848,27872,27872,27872,28896,28896,29920,29920,30944,30944,30944,31968,31968,32992,32992,32992,34016,34016,35040,35040,35040,36576,36576,36576,36576,38112,38112,38112,38112,39648,39648,39648,41184,41184,41184,41184,42720,42720,42720,42720,44256,44256,44256,45792,45792,45792},
    {416,896,1312,1888,2336,2848,3360,3872,4384,4896,5280,5920,6432,6688,7200,7712,8352,8864,9376,9888,10144,10656,11168,11936,12448,12960,13472,13472,13984,14496,15008,15520,16032,16544,17056,17568,18336,18336,19104,19872,19872,20640,21408,21408,22176,22944,22944,23968,23968,24800,24800,25824,25824,26848,26848,26848,27872,27872,28896,28896,29920,29920,30944,30944,31968,31968,32992,32992,34016,34016,35040,35040,35040,36576,36576,36576,38112,38112,38112,39648,39648,39648,41184,41184,41184,42720,42720,42720,44256,44256,44256,45792,45792,45792,45792,47328,47328,47328,48864,48864,48864,50304,50304,50304,51840,51840,51840,51840,54144,54144},
    {480,1024,1568,2144,2720,3232,3872,4384,5024,5536,6176,6688,7200,7712,8352,8864,9376,10144,10656,11168,11936,12448,12960,13472,13984,14496,15008,15520,16032,17056,17568,18336,18336,19104,19872,19872,20640,21408,22176,22176,22944,23968,23968,24800,24800,25824,25824,26848,27872,27872,28896,28896,29920,29920,30944,30944,31968,31968,32992,34016,34016,35040,35040,36576,36576,36576,38112,38112,38112,39648,39648,39648,41184,41184,42720,42720,42720,44256,44256,44256,45792,45792,45792,47328,47328,48864,48864,48864,50304,50304,50304,51840,51840,51840,54144,54144,54144,54144,56448,56448,56448,56448,58752,58752,58752,58752,61056,61056,61056,61056},
    {544,1184,1824,2464,3104,3744,4384,5024,5664,6176,6944,7456,8096,8864,9376,10144,10656,11424,11936,12448,13472,13984,14496,15008,16032,16544,17056,17568,18336,19104,19872,20640,20640,21408,22176,22944,22944,23968,24800,24800,25824,26848,26848,27872,27872,28896,29920,29920,30944,31968,31968,32992,32992,34016,35040,35040,36576,36576,36576,38112,38112,39648,39648,41184,41184,41184,42720,42720,44256,44256,44256,45792,45792,47328,47328,47328,48864,48864,50304,50304,51840,51840,51840,54144,54144,54144,54144,56448,56448,56448,56448,58752,58752,58752,61056,61056,61056,61056,63360,63360,63360,65664,65664,65664,65664,67968,67968,67968,67968,70272}
};

const unsigned int itbs2tbs_16qam_4[][110] =
{
  {544,1184,1824,2464,3104,3744,4384,5024,5664,6176,6944,7456,8096,8864,9376,10144,10656,11424,11936,12448,13472,13984,14496,15008,16032,16544,17056,17568,18336,19104,19872,20640,20640,21408,22176,22944,22944,23968,24800,24800,25824,26848,26848,27872,27872,28896,29920,29920,30944,31968,31968,32992,32992,34016,35040,35040,36576,36576,36576,38112,38112,39648,39648,41184,41184,41184,42720,42720,44256,44256,44256,45792,45792,47328,47328,47328,48864,48864,50304,50304,51840,51840,51840,54144,54144,54144,54144,56448,56448,56448,56448,58752,58752,58752,61056,61056,61056,61056,63360,63360,63360,65664,65664,65664,65664,67968,67968,67968,67968,70272},
  {576,1312,2016,2720,3488,4128,4896,5536,6176,6944,7712,8352,9120,9888,10656,11168,11936,12448,13472,13984,15008,15520,16032,17056,17568,18336,19104,19872,20640,21408,22176,22944,22944,23968,24800,24800,25824,26848,26848,27872,28896,29920,29920,30944,31968,31968,32992,34016,34016,35040,36576,36576,36576,38112,38112,39648,39648,41184,41184,42720,42720,44256,44256,45792,45792,45792,47328,47328,48864,48864,50304,50304,51840,51840,51840,54144,54144,54144,56448,56448,56448,58752,58752,58752,58752,61056,61056,61056,63360,63360,63360,65664,65664,65664,67968,67968,67968,67968,70272,70272,70272,73344,73344,73344,73344,73344,76320,76320,76320,76320},
  {704,1504,2336,3104,4000,4768,5536,6432,7200,8096,8864,9632,10400,11168,11936,12960,13984,14496,15520,16032,17056,17568,18336,19104,19872,21408,22176,22944,23968,23968,24800,25824,26848,27872,27872,28896,29920,30944,30944,31968,32992,34016,35040,35040,36576,36576,38112,38112,39648,39648,41184,42720,42720,44256,44256,45792,45792,47328,47328,48864,48864,50304,50304,51840,51840,54144,54144,54144,56448,56448,56448,58752,58752,58752,61056,61056,63360,63360,63360,65664,65664,65664,67968,67968,67968,70272,70272,70272,73344,73344,73344,73344,76320,76320,76320,76320,79392,79392,79392,79392,82464,82464,82464,85536,85536,85536,85536,88608,88608,88608},
  {832,1760,2720,3616,4512,5408,6432,7200,8096,9120,9888,10912,11936,12960,13472,14496,15520,16544,17568,18336,19104,19872,21408,22176,22944,23968,24800,25824,26848,26848,27872,28896,29920,30944,31968,32992,34016,35040,35040,36576,38112,38112,39648,39648,41184,42720,42720,44256,44256,45792,47328,47328,48864,48864,50304,50304,51840,51840,54144,54144,56448,56448,56448,58752,58752,61056,61056,61056,63360,63360,65664,65664,65664,67968,67968,70272,70272,70272,73344,73344,73344,76320,76320,76320,76320,79392,79392,79392,82464,82464,82464,85536,85536,85536,85536,88608,88608,88608,91680,91680,91680,94752,94752,94752,94752,97984,97984,97984,97984,101824},
  {896,1952,2976,4000,5024,6176,7200,8096,9120,10144,11424,12448,13472,14496,15520,16544,17568,18336,19872,20640,21408,22944,23968,24800,25824,26848,27872,28896,29920,30944,31968,32992,34016,35040,36576,36576,38112,39648,39648,41184,42720,42720,44256,45792,45792,47328,48864,48864,50304,51840,51840,54144,54144,56448,56448,58752,58752,58752,61056,61056,63360,63360,65664,65664,67968,67968,67968,70272,70272,73344,73344,73344,76320,76320,76320,79392,79392,79392,82464,82464,82464,85536,85536,85536,88608,88608,88608,91680,91680,91680,94752,94752,94752,97984,97984,97984,101824,101824,101824,101824,105664,105664,105664,105664,109504,109504,109504,109504,113344,113344},
  {1024,2208,3360,4512,5664,6944,7968,9120,10400,11424,12448,13984,15008,16032,17056,18336,19872,20640,22176,22944,23968,24800,25824,27872,28896,29920,30944,31968,32992,34016,35040,36576,38112,39648,39648,41184,42720,44256,44256,45792,47328,48864,48864,50304,51840,51840,54144,54144,56448,56448,58752,58752,61056,61056,63360,63360,65664,65664,67968,67968,70272,70272,73344,73344,73344,76320,76320,79392,79392,79392,82464,82464,82464,85536,85536,88608,88608,88608,91680,91680,91680,94752,94752,97984,97984,97984,101824,101824,101824,101824,105664,105664,105664,109504,109504,109504,113344,113344,113344,113344,117184,117184,117184,117184,122304,122304,122304,122304,126816,126816},
  {1120,2400,3616,4896,6176,7200,8608,9888,10912,12448,13472,14496,16032,17056,18336,19872,20640,22176,22944,24800,25824,26848,27872,28896,30944,31968,32992,34016,35040,36576,38112,39648,41184,41184,42720,44256,45792,47328,47328,48864,50304,51840,51840,54144,54144,56448,58752,58752,61056,61056,63360,63360,65664,65664,67968,67968,70272,70272,73344,73344,73344,76320,76320,79392,79392,82464,82464,82464,85536,85536,88608,88608,88608,91680,91680,94752,94752,94752,97984,97984,97984,101824,101824,101824,105664,105664,105664,109504,109504,109504,113344,113344,113344,117184,117184,117184,117184,122304,122304,122304,122304,126816,126816,126816,126816,131424,131424,131424,136032,136032}
};

const unsigned int itbs2tbs_64qam_4[][110] =
{
    {1120,2400,3616,4896,6176,7200,8608,9888,10912,12448,13472,14496,16032,17056,18336,19872,20640,22176,22944,24800,25824,26848,27872,28896,30944,31968,32992,34016,35040,36576,38112,39648,41184,41184,42720,44256,45792,47328,47328,48864,50304,51840,51840,54144,54144,56448,58752,58752,61056,61056,63360,63360,65664,65664,67968,67968,70272,70272,73344,73344,73344,76320,76320,79392,79392,82464,82464,82464,85536,85536,88608,88608,88608,91680,91680,94752,94752,94752,97984,97984,97984,101824,101824,101824,105664,105664,105664,109504,109504,109504,113344,113344,113344,117184,117184,117184,117184,122304,122304,122304,122304,126816,126816,126816,126816,131424,131424,131424,136032,136032},
    {1312,2528,3872,5152,6432,7712,9120,10400,11936,12960,14496,15520,17056,18336,19872,20640,22176,23968,24800,25824,26848,28896,29920,30944,31968,34016,35040,36576,38112,39648,39648,41184,42720,44256,45792,47328,48864,48864,50304,51840,54144,54144,56448,56448,58752,58752,61056,63360,63360,65664,65664,67968,67968,70272,70272,73344,73344,76320,76320,79392,79392,79392,82464,82464,85536,85536,88608,88608,88608,91680,91680,94752,94752,97984,97984,97984,101824,101824,101824,105664,105664,105664,109504,109504,109504,113344,113344,113344,117184,117184,117184,122304,122304,122304,122304,126816,126816,126816,126816,131424,131424,131424,136032,136032,136032,136032,140640,140640,140640,140640},
    {1344,2784,4256,5664,7200,8608,10144,11424,12960,14496,16032,17568,19104,20640,21408,22944,24800,25824,26848,28896,29920,31968,32992,35040,36576,38112,39648,41184,41184,42720,44256,45792,47328,48864,50304,51840,54144,54144,56448,58752,58752,61056,61056,63360,65664,65664,67968,70272,70272,73344,73344,76320,76320,79392,79392,82464,82464,82464,85536,85536,88608,88608,91680,91680,94752,94752,97984,97984,97984,101824,101824,105664,105664,105664,109504,109504,109504,113344,113344,117184,117184,117184,122304,122304,122304,122304,126816,126816,126816,131424,131424,131424,136032,136032,136032,140640,140640,140640,140640,146784,146784,146784,146784,151552,151552,151552,156928,156928,156928,156928},
    {1504,3104,4640,6176,7968,9376,11168,12448,14496,16032,17568,19104,20640,22176,23968,24800,26848,28896,29920,31968,32992,35040,36576,38112,39648,41184,42720,44256,45792,47328,48864,50304,51840,54144,56448,56448,58752,61056,61056,63360,65664,65664,67968,70272,70272,73344,73344,76320,76320,79392,79392,82464,85536,85536,88608,88608,91680,91680,94752,94752,97984,97984,97984,101824,101824,105664,105664,109504,109504,109504,113344,113344,117184,117184,117184,122304,122304,122304,126816,126816,126816,131424,131424,131424,136032,136032,136032,140640,140640,140640,146784,146784,146784,151552,151552,151552,151552,156928,156928,156928,162304,162304,162304,162304,169472,169472,169472,169472,175264,175264},
    {1632,3360,5152,6944,8608,10400,11936,13984,15520,17056,19104,20640,22176,23968,25824,27872,28896,30944,32992,34016,36576,38112,39648,41184,42720,44256,45792,48864,50304,51840,54144,54144,56448,58752,61056,61056,63360,65664,67968,67968,70272,73344,73344,76320,76320,79392,82464,82464,85536,85536,88608,88608,91680,91680,94752,97984,97984,101824,101824,101824,105664,105664,109504,109504,113344,113344,117184,117184,117184,122304,122304,122304,126816,126816,131424,131424,131424,136032,136032,136032,140640,140640,140640,146784,146784,146784,151552,151552,151552,156928,156928,156928,162304,162304,162304,162304,169472,169472,169472,175264,175264,175264,175264,181408,181408,181408,187552,187552,187552,187552},
    {1760,3616,5536,7456,9376,11168,12960,15008,16544,18336,20640,22176,23968,25824,27872,29920,31968,32992,35040,36576,39648,41184,42720,44256,45792,48864,50304,51840,54144,56448,58752,58752,61056,63360,65664,67968,67968,70272,73344,73344,76320,79392,79392,82464,82464,85536,88608,88608,91680,91680,94752,97984,97984,101824,101824,105664,105664,109504,109504,113344,113344,117184,117184,117184,122304,122304,126816,126816,126816,131424,131424,136032,136032,136032,140640,140640,140640,146784,146784,146784,151552,151552,156928,156928,156928,162304,162304,162304,169472,169472,169472,169472,175264,175264,175264,181408,181408,181408,187552,187552,187552,187552,195744,195744,195744,195744,195744,204096,204096,204096},
    {1952,4000,5920,7968,9888,11936,13984,16032,18336,19872,22176,23968,25824,27872,29920,31968,34016,36576,38112,39648,42720,44256,45792,48864,50304,51840,54144,56448,58752,61056,63360,63360,65664,67968,70272,73344,73344,76320,79392,79392,82464,85536,85536,88608,91680,91680,94752,97984,97984,101824,101824,105664,105664,109504,109504,113344,113344,117184,117184,122304,122304,126816,126816,126816,131424,131424,136032,136032,140640,140640,140640,146784,146784,146784,151552,151552,156928,156928,156928,162304,162304,162304,169472,169472,169472,175264,175264,175264,181408,181408,181408,187552,187552,187552,187552,195744,195744,195744,195744,204096,204096,204096,204096,211008,211008,211008,211008,220224,220224,220224},
    {2080,4256,6432,8608,10656,12960,15008,17056,19104,21408,23968,25824,27872,29920,31968,34016,36576,38112,41184,42720,45792,47328,50304,51840,54144,56448,58752,61056,63360,65664,67968,67968,70272,73344,76320,76320,79392,82464,85536,85536,88608,91680,91680,94752,97984,97984,101824,101824,105664,109504,109504,113344,113344,117184,117184,122304,122304,126816,126816,131424,131424,136032,136032,136032,140640,140640,146784,146784,146784,151552,151552,156928,156928,162304,162304,162304,169472,169472,169472,175264,175264,175264,181408,181408,181408,187552,187552,187552,195744,195744,195744,195744,204096,204096,204096,204096,211008,211008,211008,220224,220224,220224,220224,229344,229344,229344,229344,237024,237024,237024},
    {2208,4512,6944,9120,11424,13984,16032,18336,20640,22944,24800,27872,29920,31968,34016,36576,39648,41184,44256,45792,48864,50304,51840,54144,56448,58752,61056,63360,65664,67968,70272,73344,76320,79392,79392,82464,85536,88608,88608,91680,94752,97984,97984,101824,101824,105664,109504,109504,113344,113344,117184,117184,122304,122304,126816,126816,131424,131424,136032,136032,140640,140640,146784,146784,151552,151552,151552,156928,156928,162304,162304,162304,169472,169472,175264,175264,175264,181408,181408,181408,187552,187552,187552,195744,195744,195744,204096,204096,204096,204096,211008,211008,211008,220224,220224,220224,220224,229344,229344,229344,229344,237024,237024,237024,237024,246656,246656,246656,246656,255104},
    {2336,4768,7200,9632,11936,14496,17056,19872,22176,23968,26848,28896,31968,34016,36576,39648,41184,44256,45792,48864,51840,54144,56448,58752,61056,63360,65664,67968,70272,73344,76320,79392,79392,82464,85536,88608,91680,91680,94752,97984,101824,101824,105664,105664,109504,113344,113344,117184,117184,122304,126816,126816,131424,131424,136032,136032,140640,140640,146784,146784,146784,151552,151552,156928,156928,162304,162304,169472,169472,169472,175264,175264,181408,181408,181408,187552,187552,187552,195744,195744,195744,204096,204096,204096,211008,211008,211008,211008,220224,220224,220224,229344,229344,229344,229344,237024,237024,237024,246656,246656,246656,246656,255104,255104,255104,255104,266368,266368,266368,266368},
    {2464,5024,7456,10144,12448,15008,17568,20640,22944,24800,27872,29920,32992,35040,38112,41184,42720,45792,48864,50304,54144,56448,58752,61056,63360,65664,67968,70272,73344,76320,79392,82464,82464,85536,88608,91680,94752,97984,97984,101824,105664,105664,109504,113344,113344,117184,117184,122304,126816,126816,131424,131424,136032,136032,140640,140640,146784,146784,151552,151552,156928,156928,162304,162304,162304,169472,169472,175264,175264,175264,181408,181408,187552,187552,187552,195744,195744,195744,204096,204096,204096,211008,211008,211008,220224,220224,220224,220224,229344,229344,229344,237024,237024,237024,246656,246656,246656,246656,255104,255104,255104,255104,266368,266368,266368,266368,275232,275232,275232,284448},
    {2848,5920,8864,11936,15008,17568,20640,23968,26848,29920,32992,35040,38112,41184,44256,47328,50304,54144,56448,58752,61056,65664,67968,70272,73344,76320,79392,82464,85536,88608,91680,94752,97984,101824,101824,105664,109504,113344,117184,117184,122304,122304,126816,131424,131424,136032,140640,140640,146784,146784,151552,151552,156928,162304,162304,162304,169472,169472,175264,175264,181408,181408,187552,187552,195744,195744,195744,204096,204096,211008,211008,211008,220224,220224,220224,220224,229344,229344,229344,237024,237024,237024,246656,246656,246656,255104,255104,255104,266368,266368,266368,275232,275232,275232,284448,284448,284448,294848,294848,301504,301504,301504,301504,301504,301504,301504,301504,301504,301504,301504}
};

const unsigned int itbs2tbs_qpsk_8[][110] =
{
    {128,256,448,704,960,1216,1408,1664,1792,2048,2304,2624,2752,3008,3136,3392,3648,3904,4032,4288,4544,4800,4928,5184,5440,5696,5952,6208,6208,6464,6720,6976,7232,7488,7744,8000,8256,8256,8512,8768,9024,9280,9536,9792,10048,10048,10304,10560,10816,11072,11328,11328,11840,11840,12352,12352,12864,12864,12864,13376,13376,13888,13888,14400,14400,14400,14912,14912,15424,15424,15936,15936,16192,16704,16704,16704,17216,17216,17728,17728,18240,18240,18240,18752,18752,19264,19264,19776,19776,20288,20288,20288,20800,20800,21312,21312,21824,21824,21824,22336,22336,22848,22848,22848,23872,23872,23872,23872,23872,24896},
    {192,448,704,1152,1408,1664,1792,2048,2624,2752,3008,3392,3648,3904,4160,4544,4800,5056,5440,5696,5952,6208,6464,6976,7232,7488,7744,8000,8256,8512,9024,9280,9536,9792,10048,10304,10816,11072,11328,11328,11840,12352,12352,12864,12864,13376,13888,13888,14400,14400,14912,14912,15424,15936,15936,16192,16704,16704,17216,17216,17728,18240,18240,18752,18752,19264,19776,19776,20288,20288,20800,20800,21312,21824,21824,22336,22336,22848,22848,22848,23872,23872,23872,24896,24896,24896,25920,25920,25920,25920,26944,26944,26944,27968,27968,27968,27968,28992,28992,28992,30016,30016,30016,30016,31040,31040,31040,32064,32064,32064},
    {256,576,1152,1408,1664,2048,2368,2624,3008,3392,3776,4160,4544,4928,5184,5568,5952,6208,6720,6976,7488,7744,8000,8512,8768,9280,9536,10048,10304,10560,11072,11328,11840,12352,12352,12864,13376,13376,13888,14400,14400,14912,15424,15936,16192,16704,16704,17216,17728,17728,18240,18752,18752,19264,19776,20288,20288,20800,21312,21312,21824,22336,22848,22848,22848,23872,23872,24896,24896,24896,25920,25920,25920,26944,26944,26944,27968,27968,27968,28992,28992,28992,30016,30016,31040,31040,31040,32064,32064,32064,33088,33088,33088,34112,34112,34112,35136,35136,35136,36672,36672,36672,36672,36672,38208,38208,38208,38208,39744,39744},
    {320,832,1408,1664,2048,2624,3136,3520,4032,4544,4928,5440,5952,6464,6976,7232,7744,8256,8768,9280,9792,10048,10560,11072,11328,11840,12352,12864,13376,13888,14400,14912,15424,15936,16192,16704,17216,17728,18240,18752,19264,19776,20288,20288,20800,21312,21824,22336,22848,22848,23872,23872,24896,24896,25920,25920,26944,26944,27968,27968,28992,28992,28992,30016,30016,31040,31040,32064,32064,33088,33088,34112,34112,35136,35136,35136,36672,36672,36672,38208,38208,38208,38208,39744,39744,39744,41280,41280,41280,42816,42816,42816,42816,44352,44352,44352,45888,45888,45888,45888,47936,47936,47936,47936,49600,49600,49600,49600,51648,51648},
    {448,960,1664,2048,2624,3264,3904,4416,5056,5568,6208,6720,7232,8000,8512,9024,9536,10304,10816,11328,11840,12352,12864,13888,14400,14912,15424,15936,16704,17216,17728,18240,18752,19264,19776,20800,21312,21824,22336,22848,23872,23872,24896,24896,25920,25920,26944,27968,27968,28992,28992,30016,30016,31040,32064,32064,33088,33088,34112,34112,35136,35136,36672,36672,36672,38208,38208,39744,39744,39744,41280,41280,41280,42816,42816,44352,44352,44352,45888,45888,45888,47936,47936,47936,47936,49600,49600,49600,51648,51648,51648,51648,53696,53696,53696,55744,55744,55744,55744,57792,57792,57792,59840,59840,59840,59840,61888,61888,61888,63936},
    {576,1152,1792,2624,3392,4032,4800,5440,6208,6976,7744,8256,9024,9792,10560,11072,11840,12352,13376,13888,14912,15424,16192,16704,17728,18240,18752,19776,20288,21312,21824,22336,22848,23872,24896,24896,25920,26944,27968,27968,28992,30016,30016,31040,32064,32064,33088,34112,35136,35136,36672,36672,38208,38208,38208,39744,39744,41280,41280,42816,42816,44352,44352,45888,45888,45888,47936,47936,47936,49600,49600,49600,51648,51648,53696,53696,53696,55744,55744,55744,57792,57792,57792,59840,59840,59840,61888,61888,61888,63936,63936,63936,65984,65984,65984,68032,68032,70080,70080,70080,70080,73152,73152,73152,73152,76224,76224,76224,76224,76224},
    {704,1408,2048,3136,4032,4800,5696,6464,7488,8256,9024,9792,10816,11840,12352,13376,13888,14912,15936,16704,17728,18240,19264,19776,20800,21824,22336,23872,23872,24896,25920,26944,27968,27968,28992,30016,31040,32064,33088,33088,34112,35136,36672,36672,38208,38208,39744,39744,41280,41280,42816,42816,44352,45888,45888,47936,47936,47936,49600,49600,51648,51648,51648,53696,53696,55744,55744,55744,57792,57792,59840,59840,61888,61888,61888,63936,63936,65984,65984,65984,68032,68032,70080,70080,70080,73152,73152,73152,73152,76224,76224,76224,76224,79296,79296,79296,82368,82368,82368,82368,85440,85440,85440,85440,88512,88512,88512,91584,91584,91584},
    {832,1792,2624,3776,4672,5696,6720,7744,8768,9792,10560,11840,12864,13376,14400,15424,16704,17728,18752,19776,20288,21312,22336,23872,24896,25920,26944,26944,27968,28992,30016,31040,32064,33088,34112,35136,36672,36672,38208,39744,39744,41280,42816,42816,44352,45888,45888,47936,47936,49600,49600,51648,51648,53696,53696,53696,55744,55744,57792,57792,59840,59840,61888,61888,63936,63936,65984,65984,68032,68032,70080,70080,70080,73152,73152,73152,76224,76224,76224,79296,79296,79296,82368,82368,82368,85440,85440,85440,88512,88512,88512,91584,91584,91584,91584,94656,94656,94656,97728,97728,97728,100608,100608,100608,103680,103680,103680,103680,108288,108288},
    {960,2048,3136,4288,5440,6464,7744,8768,10048,11072,12352,13376,14400,15424,16704,17728,18752,20288,21312,22336,23872,24896,25920,26944,27968,28992,30016,31040,32064,34112,35136,36672,36672,38208,39744,39744,41280,42816,44352,44352,45888,47936,47936,49600,49600,51648,51648,53696,55744,55744,57792,57792,59840,59840,61888,61888,63936,63936,65984,68032,68032,70080,70080,73152,73152,73152,76224,76224,76224,79296,79296,79296,82368,82368,85440,85440,85440,88512,88512,88512,91584,91584,91584,94656,94656,97728,97728,97728,100608,100608,100608,103680,103680,103680,108288,108288,108288,108288,112896,112896,112896,112896,117504,117504,117504,117504,122112,122112,122112,122112},
    {1088,2368,3648,4928,6208,7488,8768,10048,11328,12352,13888,14912,16192,17728,18752,20288,21312,22848,23872,24896,26944,27968,28992,30016,32064,33088,34112,35136,36672,38208,39744,41280,41280,42816,44352,45888,45888,47936,49600,49600,51648,53696,53696,55744,55744,57792,59840,59840,61888,63936,63936,65984,65984,68032,70080,70080,73152,73152,73152,76224,76224,79296,79296,82368,82368,82368,85440,85440,88512,88512,88512,91584,91584,94656,94656,94656,97728,97728,100608,100608,103680,103680,103680,108288,108288,108288,108288,112896,112896,112896,112896,117504,117504,117504,122112,122112,122112,122112,126720,126720,126720,131328,131328,131328,131328,135936,135936,135936,135936,140544}
};

const unsigned int itbs2tbs_16qam8[][110] =
{
    {1088,2368,3648,4928,6208,7488,8768,10048,11328,12352,13888,14912,16192,17728,18752,20288,21312,22848,23872,24896,26944,27968,28992,30016,32064,33088,34112,35136,36672,38208,39744,41280,41280,42816,44352,45888,45888,47936,49600,49600,51648,53696,53696,55744,55744,57792,59840,59840,61888,63936,63936,65984,65984,68032,70080,70080,73152,73152,73152,76224,76224,79296,79296,82368,82368,82368,85440,85440,88512,88512,88512,91584,91584,94656,94656,94656,97728,97728,100608,100608,103680,103680,103680,108288,108288,108288,108288,112896,112896,112896,112896,117504,117504,117504,122112,122112,122112,122112,126720,126720,126720,131328,131328,131328,131328,135936,135936,135936,135936,140544},
    {1152,2624,4032,5440,6976,8256,9792,11072,12352,13888,15424,16704,18240,19776,21312,22336,23872,24896,26944,27968,30016,31040,32064,34112,35136,36672,38208,39744,41280,42816,44352,45888,45888,47936,49600,49600,51648,53696,53696,55744,57792,59840,59840,61888,63936,63936,65984,68032,68032,70080,73152,73152,73152,76224,76224,79296,79296,82368,82368,85440,85440,88512,88512,91584,91584,91584,94656,94656,97728,97728,100608,100608,103680,103680,103680,108288,108288,108288,112896,112896,112896,117504,117504,117504,117504,122112,122112,122112,126720,126720,126720,131328,131328,131328,135936,135936,135936,135936,140544,140544,140544,146688,146688,146688,146688,146688,152640,152640,152640,152640},
    {1408,3008,4672,6208,8000,9536,11072,12864,14400,16192,17728,19264,20800,22336,23872,25920,27968,28992,31040,32064,34112,35136,36672,38208,39744,42816,44352,45888,47936,47936,49600,51648,53696,55744,55744,57792,59840,61888,61888,63936,65984,68032,70080,70080,73152,73152,76224,76224,79296,79296,82368,85440,85440,88512,88512,91584,91584,94656,94656,97728,97728,100608,100608,103680,103680,108288,108288,108288,112896,112896,112896,117504,117504,117504,122112,122112,126720,126720,126720,131328,131328,131328,135936,135936,135936,140544,140544,140544,146688,146688,146688,146688,152640,152640,152640,152640,158784,158784,158784,158784,164928,164928,164928,171072,171072,171072,171072,177216,177216,177216},
    {1664,3520,5440,7232,9024,10816,12864,14400,16192,18240,19776,21824,23872,25920,26944,28992,31040,33088,35136,36672,38208,39744,42816,44352,45888,47936,49600,51648,53696,53696,55744,57792,59840,61888,63936,65984,68032,70080,70080,73152,76224,76224,79296,79296,82368,85440,85440,88512,88512,91584,94656,94656,97728,97728,100608,100608,103680,103680,108288,108288,112896,112896,112896,117504,117504,122112,122112,122112,126720,126720,131328,131328,131328,135936,135936,140544,140544,140544,146688,146688,146688,152640,152640,152640,152640,158784,158784,158784,164928,164928,164928,171072,171072,171072,171072,177216,177216,177216,183360,183360,183360,189504,189504,189504,189504,195968,195968,195968,195968,203648},
    {1792,3904,5952,8000,10048,12352,14400,16192,18240,20288,22848,24896,26944,28992,31040,33088,35136,36672,39744,41280,42816,45888,47936,49600,51648,53696,55744,57792,59840,61888,63936,65984,68032,70080,73152,73152,76224,79296,79296,82368,85440,85440,88512,91584,91584,94656,97728,97728,100608,103680,103680,108288,108288,112896,112896,117504,117504,117504,122112,122112,126720,126720,131328,131328,135936,135936,135936,140544,140544,146688,146688,146688,152640,152640,152640,158784,158784,158784,164928,164928,164928,171072,171072,171072,177216,177216,177216,183360,183360,183360,189504,189504,189504,195968,195968,195968,203648,203648,203648,203648,211328,211328,211328,211328,219008,219008,219008,219008,226688,226688},
    {2048,4416,6720,9024,11328,13888,15936,18240,20800,22848,24896,27968,30016,32064,34112,36672,39744,41280,44352,45888,47936,49600,51648,55744,57792,59840,61888,63936,65984,68032,70080,73152,76224,79296,79296,82368,85440,88512,88512,91584,94656,97728,97728,100608,103680,103680,108288,108288,112896,112896,117504,117504,122112,122112,126720,126720,131328,131328,135936,135936,140544,140544,146688,146688,146688,152640,152640,158784,158784,158784,164928,164928,164928,171072,171072,177216,177216,177216,183360,183360,183360,189504,189504,195968,195968,195968,203648,203648,203648,203648,211328,211328,211328,219008,219008,219008,226688,226688,226688,226688,234368,234368,234368,234368,244608,244608,244608,244608,253632,253632},
    {2240,4800,7232,9792,12352,14400,17216,19776,21824,24896,26944,28992,32064,34112,36672,39744,41280,44352,45888,49600,51648,53696,55744,57792,61888,63936,65984,68032,70080,73152,76224,79296,82368,82368,85440,88512,91584,94656,94656,97728,100608,103680,103680,108288,108288,112896,117504,117504,122112,122112,126720,126720,131328,131328,135936,135936,140544,140544,146688,146688,146688,152640,152640,158784,158784,164928,164928,164928,171072,171072,177216,177216,177216,183360,183360,189504,189504,189504,195968,195968,195968,203648,203648,203648,211328,211328,211328,219008,219008,219008,226688,226688,226688,234368,234368,234368,234368,244608,244608,244608,244608,253632,253632,253632,253632,262848,262848,262848,272064,272064}
} ;

const unsigned int itbs2tbs_64qam8[][110] =
{
    {2240,4800,7232,9792,12352,14400,17216,19776,21824,24896,26944,28992,32064,34112,36672,39744,41280,44352,45888,49600,51648,53696,55744,57792,61888,63936,65984,68032,70080,73152,76224,79296,82368,82368,85440,88512,91584,94656,94656,97728,100608,103680,103680,108288,108288,112896,117504,117504,122112,122112,126720,126720,131328,131328,135936,135936,140544,140544,146688,146688,146688,152640,152640,158784,158784,164928,164928,164928,171072,171072,177216,177216,177216,183360,183360,189504,189504,189504,195968,195968,195968,203648,203648,203648,211328,211328,211328,219008,219008,219008,226688,226688,226688,234368,234368,234368,234368,244608,244608,244608,244608,253632,253632,253632,253632,262848,262848,262848,272064,272064},
    {2624,5056,7744,10304,12864,15424,18240,20800,23872,25920,28992,31040,34112,36672,39744,41280,44352,47936,49600,51648,53696,57792,59840,61888,63936,68032,70080,73152,76224,79296,79296,82368,85440,88512,91584,94656,97728,97728,100608,103680,108288,108288,112896,112896,117504,117504,122112,126720,126720,131328,131328,135936,135936,140544,140544,146688,146688,152640,152640,158784,158784,158784,164928,164928,171072,171072,177216,177216,177216,183360,183360,189504,189504,195968,195968,195968,203648,203648,203648,211328,211328,211328,219008,219008,219008,226688,226688,226688,234368,234368,234368,244608,244608,244608,244608,253632,253632,253632,253632,262848,262848,262848,272064,272064,272064,272064,281280,281280,281280,281280},
    {2688,5568,8512,11328,14400,17216,20288,22848,25920,28992,32064,35136,38208,41280,42816,45888,49600,51648,53696,57792,59840,63936,65984,70080,73152,76224,79296,82368,82368,85440,88512,91584,94656,97728,100608,103680,108288,108288,112896,117504,117504,122112,122112,126720,131328,131328,135936,140544,140544,146688,146688,152640,152640,158784,158784,164928,164928,164928,171072,171072,177216,177216,183360,183360,189504,189504,195968,195968,195968,203648,203648,211328,211328,211328,219008,219008,219008,226688,226688,234368,234368,234368,244608,244608,244608,244608,253632,253632,253632,262848,262848,262848,272064,272064,272064,281280,281280,281280,281280,293568,293568,293568,293568,303104,303104,303104,313856,313856,313856,313856},
    {3008,6208,9280,12352,15936,18752,22336,24896,28992,32064,35136,38208,41280,44352,47936,49600,53696,57792,59840,63936,65984,70080,73152,76224,79296,82368,85440,88512,91584,94656,97728,100608,103680,108288,112896,112896,117504,122112,122112,126720,131328,131328,135936,140544,140544,146688,146688,152640,152640,158784,158784,164928,171072,171072,177216,177216,183360,183360,189504,189504,195968,195968,195968,203648,203648,211328,211328,219008,219008,219008,226688,226688,234368,234368,234368,244608,244608,244608,253632,253632,253632,262848,262848,262848,272064,272064,272064,281280,281280,281280,293568,293568,293568,303104,303104,303104,303104,313856,313856,313856,324608,324608,324608,324608,338944,338944,338944,338944,350528,350528},
    {3264,6720,10304,13888,17216,20800,23872,27968,31040,34112,38208,41280,44352,47936,51648,55744,57792,61888,65984,68032,73152,76224,79296,82368,85440,88512,91584,97728,100608,103680,108288,108288,112896,117504,122112,122112,126720,131328,135936,135936,140544,146688,146688,152640,152640,158784,164928,164928,171072,171072,177216,177216,183360,183360,189504,195968,195968,203648,203648,203648,211328,211328,219008,219008,226688,226688,234368,234368,234368,244608,244608,244608,253632,253632,262848,262848,262848,272064,272064,272064,281280,281280,281280,293568,293568,293568,303104,303104,303104,313856,313856,313856,324608,324608,324608,324608,338944,338944,338944,350528,350528,350528,350528,362816,362816,362816,375104,375104,375104,375104},
    {3520,7232,11072,14912,18752,22336,25920,30016,33088,36672,41280,44352,47936,51648,55744,59840,63936,65984,70080,73152,79296,82368,85440,88512,91584,97728,100608,103680,108288,112896,117504,117504,122112,126720,131328,135936,135936,140544,146688,146688,152640,158784,158784,164928,164928,171072,177216,177216,183360,183360,189504,195968,195968,203648,203648,211328,211328,219008,219008,226688,226688,234368,234368,234368,244608,244608,253632,253632,253632,262848,262848,272064,272064,272064,281280,281280,281280,293568,293568,293568,303104,303104,313856,313856,313856,324608,324608,324608,338944,338944,338944,338944,350528,350528,350528,362816,362816,362816,375104,375104,375104,375104,391488,391488,391488,391488,391488,408192,408192,408192},
    {3904,8000,11840,15936,19776,23872,27968,32064,36672,39744,44352,47936,51648,55744,59840,63936,68032,73152,76224,79296,85440,88512,91584,97728,100608,103680,108288,112896,117504,122112,126720,126720,131328,135936,140544,146688,146688,152640,158784,158784,164928,171072,171072,177216,183360,183360,189504,195968,195968,203648,203648,211328,211328,219008,219008,226688,226688,234368,234368,244608,244608,253632,253632,253632,262848,262848,272064,272064,281280,281280,281280,293568,293568,293568,303104,303104,313856,313856,313856,324608,324608,324608,338944,338944,338944,350528,350528,350528,362816,362816,362816,375104,375104,375104,375104,391488,391488,391488,391488,408192,408192,408192,408192,422016,422016,422016,422016,440448,440448,440448},
    {4160,8512,12864,17216,21312,25920,30016,34112,38208,42816,47936,51648,55744,59840,63936,68032,73152,76224,82368,85440,91584,94656,100608,103680,108288,112896,117504,122112,126720,131328,135936,135936,140544,146688,152640,152640,158784,164928,171072,171072,177216,183360,183360,189504,195968,195968,203648,203648,211328,219008,219008,226688,226688,234368,234368,244608,244608,253632,253632,262848,262848,272064,272064,272064,281280,281280,293568,293568,293568,303104,303104,313856,313856,324608,324608,324608,338944,338944,338944,350528,350528,350528,362816,362816,362816,375104,375104,375104,391488,391488,391488,391488,408192,408192,408192,408192,422016,422016,422016,440448,440448,440448,440448,458688,458688,458688,458688,474048,474048,474048},
    {4416,9024,13888,18240,22848,27968,32064,36672,41280,45888,49600,55744,59840,63936,68032,73152,79296,82368,88512,91584,97728,100608,103680,108288,112896,117504,122112,126720,131328,135936,140544,146688,152640,158784,158784,164928,171072,177216,177216,183360,189504,195968,195968,203648,203648,211328,219008,219008,226688,226688,234368,234368,244608,244608,253632,253632,262848,262848,272064,272064,281280,281280,293568,293568,303104,303104,303104,313856,313856,324608,324608,324608,338944,338944,350528,350528,350528,362816,362816,362816,375104,375104,375104,391488,391488,391488,408192,408192,408192,408192,422016,422016,422016,440448,440448,440448,440448,458688,458688,458688,458688,474048,474048,474048,474048,493312,493312,493312,493312,510208},
    {4672,9536,14400,19264,23872,28992,34112,39744,44352,47936,53696,57792,63936,68032,73152,79296,82368,88512,91584,97728,103680,108288,112896,117504,122112,126720,131328,135936,140544,146688,152640,158784,158784,164928,171072,177216,183360,183360,189504,195968,203648,203648,211328,211328,219008,226688,226688,234368,234368,244608,253632,253632,262848,262848,272064,272064,281280,281280,293568,293568,293568,303104,303104,313856,313856,324608,324608,338944,338944,338944,350528,350528,362816,362816,362816,375104,375104,375104,391488,391488,391488,408192,408192,408192,422016,422016,422016,422016,440448,440448,440448,458688,458688,458688,458688,474048,474048,474048,493312,493312,493312,493312,510208,510208,510208,510208,532736,532736,532736,532736},
    {4928,10048,14912,20288,24896,30016,35136,41280,45888,49600,55744,59840,65984,70080,76224,82368,85440,91584,97728,100608,108288,112896,117504,122112,126720,131328,135936,140544,146688,152640,158784,164928,164928,171072,177216,183360,189504,195968,195968,203648,211328,211328,219008,226688,226688,234368,234368,244608,253632,253632,262848,262848,272064,272064,281280,281280,293568,293568,303104,303104,313856,313856,324608,324608,324608,338944,338944,350528,350528,350528,362816,362816,375104,375104,375104,391488,391488,391488,408192,408192,408192,422016,422016,422016,440448,440448,440448,440448,458688,458688,458688,474048,474048,474048,493312,493312,493312,493312,510208,510208,510208,510208,532736,532736,532736,532736,550464,550464,550464,568896},
    {5696,11840,17728,23872,30016,35136,41280,47936,53696,59840,65984,70080,76224,82368,88512,94656,100608,108288,112896,117504,122112,131328,135936,140544,146688,152640,158784,164928,171072,177216,183360,189504,195968,203648,203648,211328,219008,226688,234368,234368,244608,244608,253632,262848,262848,272064,281280,281280,293568,293568,303104,303104,313856,324608,324608,324608,338944,338944,350528,350528,362816,362816,375104,375104,391488,391488,391488,408192,408192,422016,422016,422016,440448,440448,440448,440448,458688,458688,458688,474048,474048,474048,493312,493312,493312,510208,510208,510208,532736,532736,532736,550464,550464,550464,568896,568896,568896,589696,589696,603008,603008,603008,603008,603008,603008,603008,603008,603008,603008,603008}
} ;

const unsigned int* itbs2tbs(LteMod mod, TxMode txMode, unsigned char layers, unsigned char itbs)
{
    const unsigned int* res = nullptr;

    if (layers == 1 || (txMode != OL_SPATIAL_MULTIPLEXING && txMode != CL_SPATIAL_MULTIPLEXING))
    {
        switch (mod)
        {
            case _QPSK:
                res = itbs2tbs_qpsk_1[itbs];
                break;
            case _16QAM:
                res = itbs2tbs_16qam_1[itbs];
                break;
            case _64QAM:
                res = itbs2tbs_64qam_1[itbs];
                break;
            default:
                throw cRuntimeError("Unknown MCS (%d) in LteAmc::itbs2tbs()", mod);
        }
    }

    // Here we are sure to use Spatial Multiplexing with more than 1 layer (2 or 4)
    else if (layers == 2)
    {
        switch (mod)
        {
            case _QPSK:
                res = itbs2tbs_qpsk_2[itbs];
                break;
            case _16QAM:
                res = itbs2tbs_16qam_2[itbs];
                break;
            case _64QAM:
                res = itbs2tbs_64qam_2[itbs];
                break;
            default:
                throw cRuntimeError("Unknown MCS (%d) in LteAmc::itbs2tbs()", mod);
        }
    }
    else if (layers == 4)
    {
        switch (mod)
        {
            case _QPSK:
                res = itbs2tbs_qpsk_4[itbs];
                break;
            case _16QAM:
                res = itbs2tbs_16qam_4[itbs];
                break;
            case _64QAM:
                res = itbs2tbs_64qam_4[itbs];
                break;
            default:
                throw cRuntimeError("Unknown MCS (%d) in LteAmc::itbs2tbs()", mod);
        }
    }

    if (res == nullptr)
        throw cRuntimeError("Invalid Level value in LteAmc::itbs2tbs()");

    return res;
}

std::vector<unsigned char> cwMapping(const TxMode& txMode, const Rank& ri, const unsigned int antennaPorts)
{
    std::vector<unsigned char> res;

    if (ri <= 1)
    {
        res.push_back(1);
    }
    else
    {
        switch (txMode)
        {
            // SISO and MU-MIMO supports only rank 1 transmission (1 layer)
            case SINGLE_ANTENNA_PORT0:
                case SINGLE_ANTENNA_PORT5:
                case MULTI_USER:
            {
                res.push_back(1);
                break;
            }

                // TX Diversity uses a number of layers equal to antennaPorts
            case TRANSMIT_DIVERSITY:
            {
                res.push_back(antennaPorts);
                break;
            }

                // Spatial MUX uses MIN(RI, antennaPorts) layers
            case OL_SPATIAL_MULTIPLEXING:
                case CL_SPATIAL_MULTIPLEXING:
            {
                int usedRi = (antennaPorts < ri) ? antennaPorts : ri;
                if (usedRi == 2)
                {
                    res.push_back(1);
                    res.push_back(1);
                }
                if (usedRi == 3)
                {
                    res.push_back(1);
                    res.push_back(2);
                }
                if (usedRi == 4)
                {
                    res.push_back(2);
                    res.push_back(2);
                }
                if (usedRi == 8)
                {
                    res.push_back(4);
                    res.push_back(4);
                }
                break;
            }

            default:
            {
                res.push_back(1);
                break;
            }
        }
    }
    return res;
}
